<?php
/**
 * Created by PhpStorm.
 * User: mr.lee
 * Date: 2018-12-26
 * Time: 18:14
 */

namespace app\api\controller;


use app\common\controller\ActionLogs;
use app\common\model\Agent;
use app\common\model\Deposit;
use app\common\model\Merchant;
use app\common\model\Paylog;
use app\common\model\Tklog;
use app\common\model\WxOpen;
use Wechat\Wxobjopen;
use Weixinpay\Wxtk;

class DepositOrder extends Pub
{

    public function orderrefund($param)
    {

//        $rarr = $this->wxreverse($param);
//        return $rarr;
        try {
            $map['id'] = $param['merchantid'];
            $User = new Merchant();
            $Agent = new Agent();
            $WxOpen = new WxOpen();
            $Deposit = new Deposit();
            $config = $User->where($map)->find();
            $deposit=$Deposit->where(['orderid' => $param['out_trade_no'],'mid'=>$param['merchantid'],'status'=>"Y"])->find();
            if($deposit){
                $agent = $Agent->where(array('id' => $config['agent']))->find();
                $users = $WxOpen->where(array('id' => $agent['wx_open_id']))->find();
                $options['wx_open_id'] = $agent['wx_open_id'];
                $weObj = new Wxtk($options);
                $notice = $weObj->generateNonceStr();
                $weObj->setParameter('appid', $users['authorizer_appid']);
                $weObj->setParameter('mch_id', $agent['partnerid']);
                $weObj->setParameter('sub_mch_id', $config['sub_mch_id']);
                $weObj->setParameter('nonce_str', $notice);
                $weObj->setParameter('out_trade_no', $param['out_trade_no']);
                $weObj->setParameter('sign_type', "HMAC-SHA256");
                $sss = $weObj->create_hash_xml($agent['partnerkey']);
                $url = 'https://api.mch.weixin.qq.com/deposit/reverse';
                $responseXml = $weObj->curl_post_ssl($url, $sss);
                $responseObj = simplexml_load_string($responseXml, 'SimpleXMLElement', LIBXML_NOCDATA);
                $responseArr = ( array )$responseObj;
                $ActionLogs = new ActionLogs();
                $ActionLogs->writelog("osapi", "clientlog", "orderrefund", "r:", $responseArr);
    //            return $responseArr;
                if ($responseArr['return_code'] == "SUCCESS" && $responseArr['result_code'] = "SUCCESS") {
                    $rarr['return_code'] = "SUCCESS";
                    $rarr['return_msg'] = "";
                    $rarr['result_code'] = 'SUCCESS';
                    $rarr['result_msg'] = "订单撤销成功";
                    $rarr['out_trade_no'] = $param['out_trade_no'];
                    $sdata['pay_statu'] = 8;
                    $Paylog = new Paylog();
                    $Paylog->save($sdata, ['orderid' => $param['out_trade_no']]);

                    $param['device_id'] = !empty($param['device_id'])?$param['device_id']:"";
                    $Deposit->where(['orderid' => $param['out_trade_no']])->update(["status" => "O",'out_user'=>$param['device_id'],'out_time'=>time()]);
                } else {
                    $rarr['return_code'] = "SUCCESS";
                    $rarr['return_msg'] = "";
                    $rarr['result_code'] = 'FAIL';
                    $rarr['result_msg'] = "订单无法撤销";
                }
            }else{
                $rarr['return_code'] = "SUCCESS";
                $rarr['return_msg'] = "";
                $rarr['result_code'] = 'FAIL';
                $rarr['result_msg'] = "请勿重复处理订单";
            }
        } catch (\Exception $e) {
            $rarr['return_code'] = "FAIL";
            $rarr['return_msg'] = "系统错误" . $e->getMessage();
            $rarr['result_code'] = 'FAIL';
            $rarr['result_msg'] = "系统错误" . $e->getMessage();
        }
        return $rarr;

    }

    //撤销订单操作
    public function wxreverse($param)
    {
        try {
//            $map['id'] = $param['merchantid'];
//            $User = new Merchant();
//            $Agent = new Agent();
//            $WxOpen = new WxOpen();
//            $config = $User->where($map)->find();
//
//            $agent = $Agent->where(array('id' => $config['agent']))->find();
//            $users = $WxOpen->where(array('id' => $agent['wx_open_id']))->find();
//            $options['wx_open_id'] = $agent['wx_open_id'];
//            $weObj = new Wxtk($options);
//            $notice = $weObj->generateNonceStr();
//            $weObj->setParameter('appid', $users['authorizer_appid']);
//            $weObj->setParameter('mch_id', $agent['partnerid']);
//            $weObj->setParameter('sub_mch_id', $config['sub_mch_id']);
//            $weObj->setParameter('nonce_str', $notice);
//            $weObj->setParameter('out_trade_no', $param['out_trade_no']);
//            $weObj->setParameter('sign_type', "HMAC-SHA256");
//            $sss = $weObj->create_hash_xml($agent['partnerkey']);
//            $url = 'https://api.mch.weixin.qq.com/deposit/reverse';
//            $responseXml = $weObj->curl_post_ssl($url, $sss);
//            $responseObj = simplexml_load_string($responseXml, 'SimpleXMLElement', LIBXML_NOCDATA);
//            $responseArr = ( array )$responseObj;
//            return $responseArr;
//            if ($responseArr['return_code'] == "SUCCESS" && $responseArr['result_code'] = "SUCCESS") {
//                $rarr['return_code'] = "SUCCESS";
//                $rarr['return_msg'] = "";
//                $rarr['result_code'] = 'SUCCESS';
//                $rarr['result_msg'] = "订单撤销成功";
//                $rarr['out_trade_no'] = $param['out_trade_no'];
//                $sdata['pay_statu'] = 8;
//                $Paylog = new Paylog();
//                $Paylog->save($sdata, ['orderid' => $param['out_trade_no']]);
//                $Deposit = new Deposit();
//                $Deposit->save(["status" => "O"], ['orderid' => $param['out_trade_no']]);
//            } else {
//                $rarr['return_code'] = "SUCCESS";
//                $rarr['return_msg'] = "";
//                $rarr['result_code'] = 'FAIL';
//                $rarr['result_msg'] = "订单无法撤销";
//            }
                $rarr['return_code'] = "SUCCESS";
                $rarr['return_msg'] = "";
                $rarr['result_code'] = 'FAIL';
                $rarr['result_msg'] = "订单无法撤销";

        } catch (\Exception $e) {
            $rarr['return_code'] = "FAIL";
            $rarr['return_msg'] = "系统错误" . $e->getMessage();
            $rarr['result_code'] = 'FAIL';
            $rarr['result_msg'] = "系统错误" . $e->getMessage();
        }
        return $rarr;
    }

    //订单退款
    public function wxorderrefund($param)
    {

        try {

            $map['id'] = $param['merchantid'];
            $User = new Merchant();
            $Agent = new Agent();
            $WxOpen = new WxOpen();
            $Paylog = new Paylog();
            $config = $User->where($map)->find();
            $agent = $Agent->where(array('id' => $config['agent']))->find();
            $users = $WxOpen->where(array('id' => $agent['wx_open_id']))->find();
            $order = $Paylog->where('orderid', $param['out_trade_no'])->find();
            $options['wx_open_id'] = $agent['wx_open_id'];
            $weObj = new Wxtk($options);
            if (isset($param['client_source']) && $param['client_source'] !== 1) {
                $tk_orderid = $param['other_refund_no'];
                $params['client_source'] = $param['client_source'];
                $params['other_tk_orderid'] = $param['client_source'];
            } else {
                $tk_orderid = $this->getorderid($param['merchantid']);
            }
            $notice = $weObj->generateNonceStr();
            $weObj->setParameter('appid', $users['authorizer_appid']);
            $weObj->setParameter('mch_id', $agent['partnerid']);
            $weObj->setParameter('sub_mch_id', $config['sub_mch_id']);
            $weObj->setParameter('nonce_str', $notice);
            $weObj->setParameter('refund_desc', isset($param['refund_desc']) ? $param['refund_desc'] : 0);
            $weObj->setParameter('out_trade_no', $param['out_trade_no']);
            $weObj->setParameter('out_refund_no', $tk_orderid);
            $weObj->setParameter('total_fee', $order['price'] * 100);
            $weObj->setParameter('refund_fee', $param['refund_fee'] * 100);
            $weObj->setParameter('sign_type', "HMAC-SHA256");

            $sss = $weObj->create_hash_xml($agent['partnerkey']);
            $url = 'https://api.mch.weixin.qq.com/deposit/refund';
            $responseXml = $weObj->curl_post_ssl($url, $sss);

            $responseObj = simplexml_load_string($responseXml, 'SimpleXMLElement', LIBXML_NOCDATA);
            //转换成数组
            $params['orderid'] = $param['out_trade_no'];
            $params['mid'] = $param['merchantid'];
            $params['addtime'] = time();
            $params['action_user'] = $param['device_id'];
            $params['tk_fs'] = $param['source'];
            $params['pid'] = $order['id'];
            $params['refund_fee'] = $param['refund_fee'];
            $params['tk_orderid'] = $tk_orderid;


            $responseArr = ( array )$responseObj;
            file_put_contents('/data2/html/osapi/abc.log',json_encode($responseArr),8);
            if ($responseArr['return_code'] == 'SUCCESS' && $responseArr['result_code'] == "SUCCESS") {
                    $rarr['return_code'] = "SUCCESS";
                    $rarr['result_code'] = "SUCCESS";
                    $rarr['return_msg'] = "退款成功";
                    $rarr['result_msg'] = "退款成功";
                    $rarr['out_trade_no'] = $order['orderid'];
                    $rarr['out_refund_no'] = $responseArr['out_refund_no'];
                    $rarr['trade_no'] = $order['trade_no'];
                    $rarr['total_fee'] = $order['price'];//支付金额
                    $rarr['refund_fee'] = $param['refund_fee'];//退款金额
                    $rarr['channel'] = $order['pay_fs'];//支付方式
                    $params['tk_status'] = 1;
                    $params['sys_orderid'] = $responseArr['refund_id'];
                    if ($order['price'] == $order['tk_price'] + $param['refund_fee']) {
                        $sedata['pay_statu'] = 2;
                        $sedata['tk_status'] = 1;
                    } else {
                        $sedata['pay_statu'] = 3;
                        $sedata['tk_status'] = 2;
                    }
                    $sedata['tk_price'] = $order['tk_price'] + $param['refund_fee'];
                    if($order['pay_statu']==6){
                        $Paylog->save($sedata, ['orderid' => $order['orderid']."_YJ"]);
                    }else{
                    $Paylog->save($sedata, ['orderid' => $order['orderid']]);
                    }
//                } else {
//                    $rarr['return_code'] = "SUCCESS";
//                    $rarr['result_code'] = "FAIL";
//                    $rarr['return_msg'] = $responseArr['return_msg'];
//                    $rarr['result_msg'] = $responseArr['return_msg'];
//                    $params['tk_status'] = 3;
//                }
                $params['tk_info'] = json_encode($responseArr);
            } else {
                if (isset($responseArr['err_code_des'])) {
                    $errmsg = $responseArr['err_code_des'];
                } elseif (isset($responseArr['return_msg'])) {
                    $errmsg = translate($responseArr['return_msg']);
                } else {
                    $errmsg = "未知错误";
                }
                $rarr['return_code'] = "SUCCESS";
                $rarr['result_code'] = "FAIL";
                $rarr['return_msg'] = $errmsg;
                $rarr['result_msg'] = $errmsg;
            }
            $params['tk_info'] = json_encode($responseArr);
            $Tklog = new Tklog();

            $Tklog->save($params);
//                } else {
//                    $rarr['return_code'] = "SUCCESS";
//                    $rarr['result_code'] = "FAIL";
//                    $rarr['return_msg'] = "该账户没有退款权限";
//                    $rarr['result_msg'] = "该账户没有退款权限";
//                }
//            } else {
//                $rarr['return_code'] = "SUCCESS";
//                $rarr['result_code'] = "FAIL";
//                $rarr['return_msg'] = "退款密码错误";
//                $rarr['result_msg'] = "退款密码错误";
//            }

        } catch (\Exception $e) {
            $rarr['return_code'] = "FAIL";
            $rarr['return_msg'] = '系统错误';
            $rarr['result_code'] = 'FAIL';
            $rarr['result_msg'] = '系统错误' . $e->getMessage();
        }
        return $rarr;
    }

    //订单退款查询
    public function wx_order_refund_query($param)
    {
        $Paylog = new Paylog();
        $mab['pay_statu'] = array('neq', 0);

        $mab['orderid'] = $param['out_trade_no'];

        $paylog = $Paylog->where($mab)->find();

        $Merchant = new Merchant();
        $Agent = new Agent();
        $WxOpen = new WxOpen();
        $map['id'] = $param['merchantid'];

        $config = $Merchant->where($map)->find();
        $agent = $Agent->where(array('id' => $config['agent']))->find();
        $users = $WxOpen->where(array('id' => $agent['wx_open_id']))->find();
        $userwx = $WxOpen->where(array('id' => $config['wx_open_id']))->find();

        $options = array(
            'appid' => $users['authorizer_appid'], // 填写高级调用功能的app id
            'partnerid' => $agent['partnerid'], // 财付通商户身份标识
            'partnerkey' => $agent['partnerkey'], // 财付通商户权限密钥Key
        );

        $weObj = new Wxobjopen($options);
        $appid = $users['authorizer_appid'];
        $mch_id = $agent['partnerid'];
        $out_trade_no = $paylog['orderid'];
        $out_refund_no = $param['refund_no'];
        $nonce_str = $weObj->generateNonceStr();
        $sub_mch_id = $config['sub_mch_id'];
        $sub_appid = $userwx['authorizer_appid'];
        $arrdata = array(
            "appid" => $appid,
            "mch_id" => $mch_id,
            "sub_appid" => $sub_appid,
            "out_refund_no" => $out_refund_no,
            "sub_mch_id" => $sub_mch_id,
            "nonce_str" => $nonce_str,
            "out_trade_no" => $out_trade_no,
            "sign_type" => "HMAC-SHA256"
        );
        $pay_xml = $weObj->createWxPackageXml($arrdata);
//        $pay_xml = $weObj->createOrderrefundXml($appid, $mch_id, $sub_appid, $sub_mch_id, $out_refund_no, $out_trade_no, $nonce_str);
        $url = "https://api.mch.weixin.qq.com/deposit/refundquery";
        $payorder_xml = $weObj->send_post($url, $pay_xml);
        $rarr['return_code'] = "SUCCESS";
        if ($payorder_xml['return_code'] == "SUCCESS") {
            if ($payorder_xml['result_code'] == "SUCCESS") {
                $rarr['result_code'] = "SUCCESS";
                $rarr['return_msg'] = "查询成功";

                $rarr['result_msg'] = "查询成功";
                $rarr['out_trade_no'] = $paylog['orderid'];
                $rarr['channel'] = $paylog['pay_fs'];
                $rarr['refund_no'] = $payorder_xml["out_refund_no_0"];
                $rarr['out_refund_no'] = $payorder_xml["out_refund_no_0"];
                $rarr['refund_fee'] = $payorder_xml["refund_fee_0"] / 100;
                $rarr['trade_no'] = $paylog['trade_no'];

            } else {
                $rarr['result_code'] = "FAIL";
                if (isset($payorder_xml['result_msg'])) {
                    $rarr['result_msg'] = $payorder_xml['result_msg'];
                    $rarr['return_msg'] = $payorder_xml['return_msg'];
                } elseif (isset($payorder_xml['err_code'])) {
                    $rarr['result_msg'] = $payorder_xml['err_code'];
                    $rarr['return_msg'] = $payorder_xml['err_code'];
                }
            }

        } else {
            $rarr['result_code'] = "FAIL";
            if (isset($payorder_xml['result_msg'])) {
                $rarr['result_msg'] = $payorder_xml['result_msg'];
                $rarr['return_msg'] = $payorder_xml['return_msg'];

            } elseif ($payorder_xml['err_code']) {
                $rarr['result_msg'] = $payorder_xml['err_code'];
                $rarr['return_msg'] = $payorder_xml['err_code'];
            }
        }
        return $rarr;

    }

    public function getdepositlist($param)
    {
        $Deposit = new Deposit();
        $map['a.mid'] = $param['merchantid'];
        //电话或房间号
        if (!empty($param['search'])) {
            $map['a.tel|a.room|a.orderid'] = $param['search'];
        }
        //状态
        if (!empty($param['status'])) {
            $map['a.status'] = $param['status'];
        }
        //END
        $page = ($param['page'] - 1) * 10;
        $list = $Deposit->alias('a')
            ->join('wn_paylog b','a.orderid=b.orderid','left')
            ->field('a.*,b.pay_fs')
            ->order('a.create_time desc')
            ->where($map)->limit($page, 10)->select();
        $total_num = $Deposit->alias('a')->where($map)->count();
        $total_fee = $Deposit->alias('a')->where($map)->sum('total_fee');
        $out_fee = $Deposit->alias('a')->where($map)->sum('out_fee');
        if ($list) {
            foreach ($list as $k=>$v){
                $list[$k]['pay_fs_ch'] = getpayfs($v['pay_fs']);
                $list[$k]['channel'] = $v['pay_fs'];
                $list[$k]['depostit_type'] = deposit_pay_status($v['status']);
                $list[$k]['xingming'] = empty($v['xingming'])?"空":$v['xingming'];
                $list[$k]['tel'] = empty($v['tel'])?"空":$v['tel'];

            }
            $rarr['return_code'] = "SUCCESS";
            $rarr['return_msg'] = "";
            $rarr['result_code'] = 'SUCCESS';
            $rarr['result_msg'] = "获取成功";
            $rarr['info'] = $list;
            $rarr['total'] = $total_num;
            $rarr['total_num'] = $total_num;
            $rarr['total_fee'] = $total_fee;
            $rarr['out_fee'] = $out_fee;
        } else {
            $rarr['return_code'] = "SUCCESS";
            $rarr['return_msg'] = "";
            $rarr['result_code'] = 'FAIL';
            $rarr['result_msg'] = "没有查询到相关记录";
        }
        return $rarr;
    }

    public function getdeposit_info($param)
    {
        $Deposit = new Deposit();
        $map['a.mid'] = $param['merchantid'];
        $map['a.orderid'] =$param['orderid'];
//        $map['status'] = "Y";
        $info = $Deposit->alias('a')
//            ->join('wn_paylog b','a.orderid=b.orderid','left')        ,b.pay_fs,b.kuantai,b.d_cashier,b.pay_statu,b.orderno
            ->field('a.*')->where($map)->find();
//        $res_data['sql'] = $Deposit->getLastSql();
        if ($info) {
//            $info['channel'] = $info['pay_fs'];
//            $info['pay_statu_ch'] = getpaystatus($info['pay_statu']);
            $info['channel'] = "20";
            $info['order_cate'] = '预授权订单';
            $info['refund_fee'] = $info['status'] == "O"?$info['total_fee']-$info['out_fee']:0.00;         //退款   总金额减去消费等于退款
            $info['depostit_type'] = deposit_pay_status($info['status']);
            if ($info['status'] == 'Y') {
                $info['order_status'] = "已支付";
            }elseif ($info['status'] == 'N'){
                $info['order_status'] = "未支付";
            }elseif ($info['status'] == 'O'){
                $info['order_status'] = "已退房";
            }else{
                $info['order_status'] = "未知";
            }
            $info['source'] = '押金';
            $info['out_time'] = !empty($info['out_time'])?date('Y-m-d H:i:s',$info['out_time']):"";
            //END
            $info['xingming'] = empty($info['xingming'])?"空":$info['xingming'];
            $info['tel'] = empty($info['tel'])?"空":$info['tel'];
            //END
            $res_data['return_code'] = "SUCCESS";
            $res_data['return_msg'] = "";
            $res_data['result_code'] = 'SUCCESS';
            $res_data['result_msg'] = "获取成功";
            $res_data['info'] = _unsetNull($info);
        } else {
            $res_data['return_code'] = "SUCCESS";
            $res_data['return_msg'] = "";
            $res_data['result_code'] = 'FAIL';
            $res_data['result_msg'] = "没有查询到相关记录";
        }
        return $res_data;

    }

    public function getdepositinfo($param)
    {
        try {
            $ActionLogs = new ActionLogs();
            $ActionLogs->writelog("osapidev", "clientlog", "getdepositinfo", "param:", json_encode($param,JSON_UNESCAPED_UNICODE));
            $Deposit = new Deposit();
            $map['mid'] = $param['merchantid'];
            if (!empty($param['out_trade_no'])) {
                $map['orderid'] = $param['out_trade_no'];
            }
            if (isset($param['search'])) {
                if (!empty($param['search'])) {
                    $map['tel|room'] = $param['search'];
                }
            }
            $map['status']=array('neq',"N");
            $info = $Deposit->where($map)->find();

            $ActionLogs->writelog("osapidev", "clientlog", "getdepositinfo", "sql:", json_encode($Deposit->getLastSql(),JSON_UNESCAPED_UNICODE));

            //END
            if ($info) {
                $info = $info->toArray();
                //END
                $info['channel'] = "20";
                $info['order_cate'] = '预授权订单';
                $info['refund_fee'] = $info['status'] == "O" ? $info['total_fee'] - $info['out_fee'] : 0.00;         //退款   总金额减去消费等于退款
                $info['depostit_type'] = deposit_pay_status($info['status']);
                if ($info['status'] == 'Y') {
                    $info['order_status'] = "已支付";
                } elseif ($info['status'] == 'N') {
                    $info['order_status'] = "未支付";
                } elseif ($info['status'] == 'O') {
                    $info['order_status'] = "已退房";
                } else {
                    $info['order_status'] = "未知";
                }
                $info['source'] = '押金';
                $info['out_time'] = !empty($info['out_time']) ? date('Y-m-d H:i:s', $info['out_time']) : "";
                //END
                $info['xingming'] = empty($info['xingming']) ? "空" : $info['xingming'];
                $info['tel'] = empty($info['tel']) ? "空" : $info['tel'];
                //END

                $rarr['return_code'] = "SUCCESS";
                $rarr['return_msg'] = "";
                $rarr['result_code'] = 'SUCCESS';
                $rarr['result_msg'] = "获取成功";
//            $rarr['info'] = json_encode($info,JSON_UNESCAPED_UNICODE);
                $rarr['info'] = $info;
            } else {
                $rarr['return_code'] = "SUCCESS";
                $rarr['return_msg'] = "";
                $rarr['result_code'] = 'FAIL';
                $rarr['result_msg'] = "没有查询到相关记录";
            }
        } catch (\Exception $e) {
            $rarr['return_code'] = "FAIL";
            $rarr['return_msg'] = "系统错误" . $e->getMessage();
            $rarr['result_code'] = 'FAIL';
            $rarr['result_msg'] = "系统错误" . $e->getMessage();
            $ActionLogs = new ActionLogs();
            $ActionLogs->writelog("osapidev", "clientlog", "getdepositinfo", "e:", $rarr);
        }
        return $rarr;

    }

    //押金消费操作
    public function wxdepositpay($param)
    {
        try {
            $map['id'] = $param['merchantid'];
            $User = new Merchant();
            $Agent = new Agent();
            $WxOpen = new WxOpen();
            $config = $User->where($map)->find();
            $Paylog = new Paylog();
            $payinfo = $Paylog->where('orderid', $param['out_trade_no'])->find();

            $agent = $Agent->where(array('id' => $config['agent']))->find();
            $users = $WxOpen->where(array('id' => $agent['wx_open_id']))->find();
            $options['wx_open_id'] = $agent['wx_open_id'];
            $weObj = new Wxtk($options);
            $notice = $weObj->generateNonceStr();
            $weObj->setParameter('appid', $users['authorizer_appid']);
            $weObj->setParameter('mch_id', $agent['partnerid']);
            $weObj->setParameter('sub_mch_id', $config['sub_mch_id']);
            $weObj->setParameter('total_fee', $payinfo['price'] * 100);
            $weObj->setParameter('consume_fee', $param['total_fee'] * 100);
            $weObj->setParameter('nonce_str', $notice);
            $weObj->setParameter('fee_type', "CNY");
            $weObj->setParameter('out_trade_no', $param['out_trade_no']);
            $weObj->setParameter('sign_type', "HMAC-SHA256");
            $sss = $weObj->create_hash_xml($agent['partnerkey']);
            $url = 'https://api.mch.weixin.qq.com/deposit/consume';
            $responseXml = $weObj->curl_post_ssl($url, $sss);
            $responseObj = simplexml_load_string($responseXml, 'SimpleXMLElement', LIBXML_NOCDATA);
            $responseArr = ( array )$responseObj;
            $ActionLogs = new ActionLogs();
            $ActionLogs->writelog("osapi", "clientlog", "wxdepositpay", "r:", $responseArr);
            if ($responseArr['return_code'] == "SUCCESS" && $responseArr['result_code'] = "SUCCESS") {
                $params = $payinfo;
                $params['price'] = $param['total_fee'];
                $params['yf_price'] = $param['total_fee'];
                $params['payinfo'] = json_encode($responseArr);
                $params['orderid'] = $param['out_trade_no'] . "_YJ";
                $params['orderno'] = isset($responseArr['transaction_id']) ? $responseArr['transaction_id'] : "";
                $this->createneworder($params);
                $Paylog->save(['pay_statu' => 6], ['orderid' => $param['out_trade_no']]);
                $rarr['return_code'] = "SUCCESS";
                $rarr['return_msg'] = "";
                $rarr['result_code'] = 'SUCCESS';
                $rarr['result_msg'] = "订单消费成功";
                $rarr['out_trade_no'] = $param['out_trade_no'];
                $Deposit = new Deposit();
                $Deposit->where(['orderid' => $param['out_trade_no']])->update(['out_fee' => $param['total_fee'], "status" => "O",'out_user'=>$payinfo['d_cashier'],'out_time'=>time()]);
//                $sdata['pay_statu'] = 8;
//                $Paylog = new Paylog();
//                $Paylog->save($sdata, ['orderid' => $param['out_trade_no']]);

            } else {
                if ($responseArr['return_code'] == "SUCCESS") {
                    if ($responseArr['err_code'] == "SETTLING") {
                        $rarr['return_code'] = "SUCCESS";
                        $rarr['return_msg'] = "";
                        $rarr['result_code'] = 'FAIL';
                        $rarr['result_msg'] = $responseArr['err_code_des'];
                    } else {
                        $rarr['return_code'] = "SUCCESS";
                        $rarr['return_msg'] = "";
                        $rarr['result_code'] = 'FAIL';
                        $rarr['result_msg'] = "订单消费失败";
                    }
                }else{
                    $rarr['return_code'] = "SUCCESS";
                    $rarr['return_msg'] = "";
                    $rarr['result_code'] = 'FAIL';
                    $rarr['result_msg'] = $responseArr['return_msg'];
                }
            }

        } catch (\Exception $e) {
            $rarr['return_code'] = "FAIL";
            $rarr['return_msg'] = "系统错误" . $e->getMessage();
            $rarr['result_code'] = 'FAIL';
            $rarr['result_msg'] = "系统错误" . $e->getMessage();
            $ActionLogs = new ActionLogs();
            $ActionLogs->writelog("osapi", "clientlog", "wxdepositpays", "e:", $responseArr);
        }
        return $rarr;
    }

    //酒店预预授权消费后生成新的账单
    private function createneworder($param)
    {

        $Paylog = new Paylog();
        $params['pay_fs'] = 2;
        $params['add_time'] = time();
        $params['pay_statu'] = 1;
        $params['orderid'] = $param['orderid'];
        $params['mid'] = $param['mid'];
        $params['ms_orderid'] = $param['ms_orderid'];
        $params['pay_cate'] = $param['pay_cate'];
        $params['openid'] = $param['openid'];
        $params['sub_openid'] = $param['sub_openid'];
        $params['ser_openid'] = $param['ser_openid'];
        $params['yf_price'] = $param['yf_price'];
        $params['price'] = $param['price'];
        $params['service_charge'] = $param['service_charge'];
        $params['orderno'] = $param['orderno'];
        $params['pay_time'] = $param['pay_time'];
        $params['pay_way'] = $param['pay_way'];
        $params['tzzt'] = $param['tzzt'];
        $params['payinfo'] = $param['payinfo'];
        $params['g_zt'] = $param['g_zt'];
        $params['tzmsg'] = $param['tzmsg'];
        $params['kuantai'] = $param['kuantai'];
        $params['d_cashier'] = $param['d_cashier'];
        $params['tk_status'] = $param['tk_status'];
        $params['tk_price'] = $param['tk_price'];
        $params['cash_fee'] = $param['cash_fee'];
        $params['coupon_fee'] = $param['coupon_fee'];
        $params['dis_card_zk'] = $param['dis_card_zk'];
        $params['vip_card_zk'] = $param['vip_card_zk'];
        $params['dis_card_zk'] = $param['dis_card_zk'];
        $params['gel_card_zk'] = $param['gel_card_zk'];
        $params['hx_card'] = $param['gel_card_zk'];
        $params['hx_card_res'] = $param['gel_card_zk'];
        $params['hx_card_statu'] = $param['gel_card_zk'];
        $params['gel_card_zk'] = $param['gel_card_zk'];
        $params['cz_card_id'] = $param['cz_card_id'];
        $params['pay_is_put'] = $param['pay_is_put'];
        $params['card_num'] = $param['card_num'];
        $params['wsy_orderid'] = $param['wsy_orderid'];
        $params['del_statu'] = $param['del_statu'];
        $params['trade_no'] = $param['trade_no'];
        $params['huifu_ordid'] = $param['huifu_ordid'];
        $params['source'] = $param['source'];
        $params['client_source'] = $param['client_source'];
        $params['is_efp_receipt'] = $param['is_efp_receipt'];
        $params['attach'] = $param['attach'];

        $Paylog->save($params);


    }
}